package com.fanshuai2.niuke.search.dfs;
import java.util.*;

public class Board {
    static void printBooard(int[][] board) {
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                System.out.print(board[i][j]);
                if (j < board[0].length - 1) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }

    static boolean dfs(int[][] board) {
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                if (board[i][j] != 0) {
                    continue;
                }

                for (int k = 1; k <= 9; k++) {
                    if (checkBoard(board, i, j, k)) {
                        board[i][j] = k;
                        if (dfs(board)) {
                            return true;
                        }
                        board[i][j] = 0;
                    }
                }
                return false;
            }
        }

        return true;
    }

    static boolean checkBoard(int[][] board, int i, int j, int v) {
        for (int k = 0; k < 9; k++) {
            if (board[i][k] == v) {
                return false;
            }
            if (board[k][j] == v) {
                return false;
            }
        }

        int starti = i / 3 * 3;
        int startj = j / 3 * 3;
        for (i = starti; i < starti + 3; i++) {
            for (j = startj; j < startj + 3; j++) {
                if (board[i][j] == v) {
                    return false;
                }
            }
        }

        return true;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextInt()) {
            int[][] board = new int[9][9];
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    board[i][j] = in.nextInt();
                }
            }

            dfs(board);
            printBooard(board);
        }
    }
}
